package com.cyzy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dao.AttendStudentClassDao;
import com.cyzy.dao.StudentCourseDao;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Attend;
import com.cyzy.pojo.Student;
import com.cyzy.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;


    @DeleteMapping("/disabledStudent/{id}")
    public Result disabledStudent(@PathVariable Integer id){
        int i = studentService.disabledStudent(id);
        if(i == 0){
            return Result.error().message("禁用失败");
        }
        return Result.ok().message("封禁成功");
    }

//    学员信息
    @GetMapping("/selectStudents")
    public Result selectStudents(StudentCourseDao studentCourseDao){
        Page<StudentCourseDao> studentsPage = studentService.selectStudents(studentCourseDao);
        return Result.ok().data("students",studentsPage);
    }

//    查询学生
    @GetMapping("/selectAllStudent")
    public Result selectAllStudent(StudentCourseDao studentCourseDao){
        List<StudentCourseDao> studentList = studentService.selectAllStudent(studentCourseDao);
        return Result.ok().data("studentList",studentList);
    }

//    考勤管理

    @GetMapping("/attend")
    public Result attend(AttendStudentClassDao attendStudentClassDao){
        Page<AttendStudentClassDao> attendList = studentService.attend(attendStudentClassDao);
        return Result.ok().data("attendList",attendList);
    }

//    考勤管理    考勤状态
    @PostMapping("/addAttend")
    public Result addAttend(@RequestBody Attend attend){
        int i = studentService.addAttend(attend);
        return Result.ok();
    }


//    新增学员
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student){
        int i = studentService.AddStudent(student);
        System.out.println(student+"------------65");
        return Result.ok();
    }

//    重置密码
    @PutMapping("/resetPwd")
    public Result resetPwd(@RequestBody Student student){
        int i = studentService.resetPwd(student);
        return Result.ok();
    }

//    学员管理    删除
    @PutMapping("/deleteStudent")
    public Result deleteStudent(@RequestBody Student student){
        int i = studentService.deleteStudent(student);
        return Result.ok();
    }


}
